<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class FCar extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('car_model');
	}

	function overview()
	{
		$car_id = $this->uri->segment(3);
		if($car_id == '')
		{
			$q = $this->car_model->getFirstCar()->row();
			$car_id = $q->car_id;
		}

		$this->session->set_userdata('car_id',$car_id);

		$data['type'] = 'overview';
		$data['car_id'] = $car_id;
		$data['query_car'] = $this->car_model->getAllCar();
		$data['query'] = $this->car_model->getAll($car_id,'overview');
		$page["_contents"] = "frontend/car/v_car";

		$this->template->load("frontend/template/car_template",$page,$data);
	}

	function specification()
	{
		$car_id = $this->session->userdata('car_id');

		$data['type'] = 'specification';
		$data['car_id'] = $car_id;
		$data['query_car'] = $this->car_model->getAllCar();
		$data['query'] = $this->car_model->getAll($car_id,'specification');
		$page["_contents"] = "frontend/car/v_car_spec";

		$this->template->load("frontend/template/car_template",$page,$data);
	}

	function description()
	{
		$car_id = $this->session->userdata('car_id');

		$data['type'] = 'description';
		$data['car_id'] = $car_id;
		$data['query_car'] = $this->car_model->getAllCar();
		$data['query'] = $this->car_model->getAll($car_id,'description');
		$page["_contents"] = "frontend/car/v_car_desc";

		$this->template->load("frontend/template/car_template",$page,$data);
	}

	function feature()
	{
		$car_id = $this->session->userdata('car_id');

		$data['type'] = 'feature';
		$data['car_id'] = $car_id;
		$data['query_car'] = $this->car_model->getAllCar();
		$data['query'] = $this->car_model->getAll($car_id,'feature');
		$page["_contents"] = "frontend/car/v_car_feature";

		$this->template->load("frontend/template/car_template",$page,$data);
	}

	function gallery()
	{
		$car_id = $this->session->userdata('car_id');

		$r = $this->car_model->getGalleryCover($car_id)->row();
		$data["cover"] = $r->image;

		$data["query"] = $this->car_model->getGalleryByCar($car_id);
		$page["_contents"] = "frontend/car/v_car_gallery";

		$this->template->load("frontend/template/car_template",$page,$data);
	}

	function spareparts()
	{
		$car_id = $this->session->userdata('car_id');

		$data["query"] = $this->car_model->getSparepartsByCar($car_id);
		$page["_contents"] = "frontend/car/v_car_spareparts";

		$this->template->load("frontend/template/car_template",$page,$data);
	}

	function accessories()
	{
		$car_id = $this->session->userdata('car_id');

		$data["query"] = $this->car_model->getAccessoriesByCar($car_id);
		$page["_contents"] = "frontend/car/v_car_accessories";

		$this->template->load("frontend/template/car_template",$page,$data);
	}

	function accessories_detail()
	{
		$id = $this->uri->segment(3);
		
		$arr['data'] = array();
		
		$row = $this->car_model->getCarAccessoriesByID($id)->row();
		
		$arr = array(array('id' => $id, 
						   'name' => $row->name,
						   'description' => $row->description,
						   'image' => $row->image
						   )
					);
		echo json_encode($arr);
	}

	function brochure()
	{
		$car_id = $this->session->userdata('car_id');

		$data["query"] = $this->car_model->getBrochureByCar($car_id);
		$page["_contents"] = "frontend/car/v_car_brochure";

		$this->template->load("frontend/template/car_template",$page,$data);
	}

	function type()
	{
		$page["_contents"] = "frontend/car/v_car_type";

		$this->template->load("frontend/template/car_template",$page);
	}


	function load_car_list()
	{
		$arr['data'] = array();
		$query = $this->car_model->getAllCar();
		
		foreach($query->result() as $row)
		{
			$data = array();
			$link = "<a href='". base_url() ."FCar/overview/". $row->car_id ."' class='btn yellow edit-button' title='View Car Detail'><i class='fa fa-search'></i> Overview</a>";
			array_push($data,$row->series_name);
			array_push($data,$link);
			
			array_push($arr['data'],$data);
		}		
		//echo $car_id;
		echo json_encode($arr);
	}

	function custom()
	{
		$page["_contents"] = "frontend/car/v_custom";
		$car_id = $this->session->userdata('car_id');
		$data["query"] = $this->car_model->getCustomByCar($car_id);

		$this->template->load("frontend/template/car_template",$page,$data);
	}

}

/* End of file fCar.php */
/* Location: ./application/controllers/fCar.php */